package com.youyun56.gps.schedual;

import java.io.*;
import java.net.*;

public class Client {
	Socket socket;
	BufferedReader in;
	PrintWriter out;
	
	private final static char chr3 = 3;
	private final static char chr10 = 10;
	private final static char chr13 = 13;

	public Client() {}

	public static void main(String[] args) {
		Socket socket = null;
		try {
			socket = new Socket("220.162.239.162", 7001);

			final BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

			PrintWriter out = new PrintWriter(socket.getOutputStream());
//			001+chr(3) +用户名+chr(3) +密码+ chr(13) + chr(10)

			StringBuffer sb = new StringBuffer();
			sb.append("001");
			sb.append(chr3);
			sb.append("npywjk");
			sb.append(chr3);
			sb.append("npywjk");
			sb.append(chr13);
			sb.append(chr10);
			System.out.println(sb.toString());
			
//			901’+ char(3) + 设备编号+char(3) +char(3) +001+chr(13)+chr(10)
			StringBuffer gps = new StringBuffer();
			gps.append("901");
			gps.append(chr3);
			gps.append("01613385993733");
//			gps.append("01615880285723");
			
			gps.append(chr3);
			gps.append(chr3);
			gps.append("001");
			gps.append(chr13);
			gps.append(chr10);
			
			
			out.print(sb);
			out.flush();
			String str = in.readLine(); 
			System.out.println(str.charAt(4));
//			System.out.println("BACK: " + str.split(chr3));
			out.print(gps);
			out.flush();
			Thread thread = new Thread(new Runnable() {
				
				public void run() {
					// TODO Auto-generated method stuba
					try {
						System.out.println("============================");
						String str = null;
						
						while((str = in.readLine()) != null){
							System.out.println(str);
						}
						
						System.out.println("============================");

					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			});
			thread.start();
			thread.join();
			socket.close();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}